package com.tedu.ivos.vehicle.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.vehicle.pojo.dto.VehicleParam;
import com.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import com.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import com.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "车辆模块")
@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {

    @Autowired
    VehicleService vehicleService;

    @ApiOperation(value = "查询车辆信息")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult select(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息：{}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);

        return JsonResult.ok(list);
    }

    @ApiOperation(value = "新增车辆")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult insert(VehicleParam vehicleInsertParam) {
        log.debug("保存车辆：{}", vehicleInsertParam);
        vehicleService.vehicleInsert(vehicleInsertParam);

        return JsonResult.ok();
    }

    @ApiOperation(value = "解绑车辆")
    @ApiOperationSupport(order = 30)
    @PostMapping("unbind/{id}")
    public JsonResult unbindVehicle(@PathVariable Long id) {
        log.debug("解绑车辆：{}", id);
        vehicleService.unbindVehicle(id);

        return JsonResult.ok();
    }

    @ApiOperation(value = "绑定车辆")
    @ApiOperationSupport(order = 40)
    @PostMapping("bind/{geoId}/{id}")
    public JsonResult bindVehicle(@PathVariable Long geoId,
                                  @PathVariable Long id) {
        log.debug("绑定车辆：{},{}", geoId, id);
        vehicleService.bindVehicle(geoId, id);

        return JsonResult.ok();
    }

    @ApiOperation(value = "删除车辆")
    @ApiOperationSupport(order = 50)
    @DeleteMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("删除车辆：{}", id);
        vehicleService.vehicleDelete(id);

        return JsonResult.ok();
    }

}
